﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<BackupObjects.BackupRepository>" %>
<%@ Import Namespace="BackupWebRole.MVCHelpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Backups (number <%: Model.Backups.Count %>)</h2>

    <table>
        <tr>
            <th>Number</th>
            <th>Backup</th>
            <th>
                Actions
            </th>
            
        </tr>

    <% int i = 0;
        foreach (var item in Model.Backups)
        {
            i++;
            %>    
        <tr id="trbackup<%: i %>">
<td><%: i %>
<img src='<%: Url.Content("~/icos/"+item.icofilename) %>' />
</td>
        <td>
                <%: Html.DisplayFor(m=>item) %>
            </td>
            <td>
                
                <%: Html.ActionLink("Details", "Details", new {  id=item.ID })%> |
                
                <a href="javascript:confirmDelete('<%: item.ID %> ','<%: item.Name.ReplaceQuote() %>', <%: i %>)">Delete</a>|
                 <%: Html.ActionLink("Download", "ViewDetails", new { id = item.ID })%> |
            </td>
            
        </tr>
    
    <% } %>

    </table>

    <p>
        <%: Html.ActionLink("Create New", "Create") %>
    </p>
    <script type="text/javascript">
        var urldelete ='<%: Url.Action("Delete", new { id = 100 }) %>';
        function confirmDelete(id, name, rownumber) {
            
            var ret = window.confirm('do you want to delete ' + name);
            if (!ret)
                return;
            var realurl = urldelete.replace(100, id);
                        
            $.post(realurl,
                        function (text) {

                            if (text.isok) {
                                window.alert('delete succesfull');
                                $("#trbackup" + rownumber).hide();
                            }
                            else {

                                window.alert(text.message);
                            }


                        }
                    );

            


        }
    </script>
</asp:Content>

